<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Place_visit_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function getAllData($num,$offset){
        $query = $this->db->get('place_visit',$num,$offset);
      
        return $query->result();  
    } 
     function get_object($id)
    {
        $query = $this->db->get_where('place_visit', array('place_visit_id' =>$id));
        return $query->row();
    }
    
    function delete($id){
          $this->db->where('place_visit_id',$id);
          $query = $this->db->delete('place_visit');
          if($query){
              return true;
          }else{
              return false;
          }
    }
	function deleted($id){
          $this->db->where('place_visit_id',$id);
		  $data=array('bl_active'=>'-1');
          $query = $this->db->update('place_visit',$data);
          if($query){
              return true;
          }else{
              return false;
          }
    }
    function get_list_permit(){
        return $this->db->get('permission')->result();
    }
   
   function saveData($place_visit_id,$data){
             if($place_visit_id!=0){
                    $this->db->where('place_visit_id',$place_visit_id);
                    if($this->db->update('place_visit',$data)){
                         return true;
                    }else{
                         return false;
                    }
             }else{
                    if($this->db->insert('place_visit',$data)){
                        return $this->db->insert_id();
                        
                    }else{
                        return false;
                    }
            }
    }
    function get_num_data($arr_search){
            /*Begin search*/
            switch($arr_search['field_search'])
            {
                    case 'title':
                            $this->db->like('title',$arr_search['key_search']);
                            break ;
					case 'description':
                            $this->db->like('description',$arr_search['key_search']);
                            break ;
					case 'city_name':
                            $this->db->like('city.name',$arr_search['key_search']);
                            break ;
                    
            }
            /*End search*/
             $this->db->where('place_visit.bl_active',1);
			 $this->db->join('city','city.city_id=place_visit.city_id');
             $query = $this->db->get('place_visit');
             return $query->num_rows();
    }
    function get_all_data($num,$offset,$arr_search)
    {
             $this->db->select("place_visit.*");
			/*Begin search*/
            switch($arr_search['field_search'])
            {
                    case 'title':
                            $this->db->like('title',$arr_search['key_search']);
                            break ;
					 case 'description':
                            $this->db->like('description',$arr_search['key_search']);
                            break ;
					 case 'city_name':
                            $this->db->like('city.name',$arr_search['key_search']);
                            break ;
            }
            /*End search*/
			$this->db->join('city','city.city_id=place_visit.city_id');
            $this->db->where('place_visit.bl_active <> ',-1);
			$this->db->order_by('place_visit.place_visit_id','DESC');
            $query = $this->db->get('place_visit',$num,$offset);
			
             return $query->result();
    }
		function optionCity($value=0){
		   $query = $this->db->get('place_visit');
		   $category_arr = $query->result();
		   $str_opt = "";
		   foreach($category_arr as $item_opt){
				$str_opt .="<option value='".$item_opt->place_visit_id."'".(($value==$item_opt->place_visit_id)?" selected":"")."> ".$item_opt->name."</option>";
			}
			return $str_opt;
	   }
       function getCityName($city_id=0) {
        $this->db->select("name");
        $this->db->where('city_id',$city_id);
        $query = $this->db->get("city");
        return $query->row();
    }
	  
  }
?>
